/*
 * Copyright 2008 Slava Chernyak
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. 
 */
package com.chernyak.DataAdapter.types;

public class CharDecl extends PrimitiveTypeDecl {

	public CharDecl(String name, boolean compare, int ln) {
		super(name, compare, ln);
	}
	
	@Override
	public void lowerDeclarations(StringBuilder sink) {
		sink.append("public char " + name + " = \\u0000;");
	}

	public void lowerRead(StringBuilder sink, int arrayDim) {
		super.lowerRead(sink, arrayDim);
		sink.append("d.readChar();");
	}
	
	public void lowerWrite(StringBuilder sink, int arrayDim) {
		sink.append("d.writeChar(");
		super.lowerWrite(sink, arrayDim);
		sink.append( ");");
	}
	
	public void lowerHashCode(StringBuilder sink) {
		if (compare) {
			sink.append("__da_hashcode +=  new Char(" + name + ").hashCode();");
		}
	}
	
	public void lowerParse(StringBuilder sink, int arrayDim) {
		if (arrayDim != 1) { 
			super.lowerParse(sink, arrayDim);
		}
		sink.append("__da_tokens.nextToken().charAt(0);");
	}
	
	protected String getTypeName() {
		return "char";
	}
	
	protected String getBoxedTypeName() {
		return "Char";
	}

}
